/**
 * Compute the Greatest Common Divisor (GCD) using the Euclid's algorthm
 * If b=0 then return a else return gcd(a, a % b)
 * Suggested exercises:
 * - Implement the version based on subtraction. Use the fact gcd(a,b) = gcd(a-b,b)
 *   That is, repeatedly replace the larger by subtracting the smaller from it 
 *   until the two numbers become equal.
 * - Avod the infinite loop when one of the numbers is 0
 */
import java.util.Scanner;

public class Gcd
{
   public static void main (String[] args) 
   {
       Scanner scan = new Scanner(System.in);
       int a, b, t;
       System.out.print("Enter first integer: ");
       a = scan.nextInt();
       System.out.print("Enter second integer: ");
       b = scan.nextInt();

       while (b > 0) 
       { 
           t = a % b; 
           a = b; 
           b = t; 
       }

       System.out.println("Their GCD is: " + a);
   }
}
